package com.taikang.hmp.hbusiness.doctor.hplan.action;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.taikang.hmp.frame.common.TKException;
import com.taikang.hmp.frame.common.datastructre.Dto;
import com.taikang.hmp.frame.common.datastructre.support.BaseDto;
import com.taikang.hmp.frame.common.datastructre.support.ResponseDto;
import com.taikang.hmp.frame.common.web.action.BaseAction;
import com.taikang.hmp.hbusiness.doctor.hplan.bean.Hdbzdchealthplan;
import com.taikang.hmp.hbusiness.doctor.hplan.service.IHealthPlanService;

public class HealthPlanAction extends BaseAction{
	
	private static final long serialVersionUID = 1L;

	private static Logger logger = LoggerFactory.getLogger(HealthPlanAction.class);

	private IHealthPlanService  healthPlanService; 
	

	@Override
	public String executeAction() {
		if ("getHealthPlanList".equals(requestDto.getMethod())){
			logger.info("--获取健康计划: getHealthPlanList method --");
			return getHealthPlanList();
		}else if("addHealthPlan".equals(requestDto.getMethod())){
			logger.info("--增加健康计划: addHealthPlan method --");
			return addHealthPlan();
		}else if("updateHealthPlando".equals(requestDto.getMethod())){
			logger.info("--更新健康计划执行情况: updateHealthPlando method --");
			return updateHealthPlando();
		}else if("updateHealthPlan".equals(requestDto.getMethod())){
			logger.info("--更改健康计划: updateHealthPlan method --");
			return updateHealthPlan();
		}else if("deleteHealthPlan".equals(requestDto.getMethod())){
			logger.info("--删除健康计划: deleteHealthPlan method --");
			return deleteHealthPlan();
		}else if("getTime".equals(requestDto.getMethod())){
			logger.info("--获取当前时间: getTime method --");
			return getTime();
		}else {
			throw new TKException("no support method:" + requestDto.getMethod());
		}
	}
	
	private String getTime() {
		
		ResponseDto responseDto = new ResponseDto();
		Dto paramDto = requestDto.getRequestlist().get(0);
		paramDto = super.appendRequestBase(paramDto, requestDto);
		
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		String time = sdf.format(new Date());
		Dto resultDto = new BaseDto();
		resultDto.put("time", time);
		responseDto.pushResultDto(resultDto);
		super.setDataMap(responseDto);	
		return SUCCESS;
	}


	private String deleteHealthPlan() {
		ResponseDto responseDto=new ResponseDto();
		Dto paramDto = requestDto.getRequestlist().get(0);
		paramDto = super.appendRequestBase(paramDto, requestDto);
		
		healthPlanService.deleteHealthPlan(paramDto);
		super.setDataMap(responseDto);
		return SUCCESS;
	}


	private String updateHealthPlan() {
		ResponseDto responseDto=new ResponseDto();
		Dto paramDto = requestDto.getRequestlist().get(0);
		paramDto = super.appendRequestBase(paramDto, requestDto);
		
		healthPlanService.updateHealthPlan(paramDto);
		super.setDataMap(responseDto);
		return SUCCESS;
	}


	public String getHealthPlanList(){
		ResponseDto responseDto=new ResponseDto();
		Dto paramDto = requestDto.getRequestlist().get(0);
		paramDto = super.appendRequestBase(paramDto, requestDto);
		
		List<Dto> resultList=healthPlanService.getHealthPlanList(paramDto);
		Dto resultDto = new BaseDto();
		resultDto.put("resultlist", resultList);
		responseDto.pushResultDto(resultDto);
		super.setDataMap(responseDto);
		return SUCCESS;
		
	}

	public String addHealthPlan(){
		ResponseDto responseDto=new ResponseDto();
		Dto paramDto = requestDto.getRequestlist().get(0);
		paramDto = super.appendRequestBase(paramDto, requestDto);
		
		Hdbzdchealthplan plan = healthPlanService.addHealthPlan(paramDto);
		Dto result = new BaseDto();
		result.put("planID", plan.getPlan_id());
		responseDto.pushResultDto(result);
		super.setDataMap(responseDto);
		return SUCCESS;
	}
	
	public String updateHealthPlando(){
		ResponseDto responseDto=new ResponseDto();
		Dto paramDto = requestDto.getRequestlist().get(0);
		paramDto = super.appendRequestBase(paramDto, requestDto);
		
		healthPlanService.updateHealthPlando(paramDto);
		super.setDataMap(responseDto);
		return SUCCESS;
	}
	
	
	
	

	public void setHealthPlanService(IHealthPlanService healthPlanService) {
		this.healthPlanService = healthPlanService;
	}

}
